package com.project.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.entity.VerifyEntity;
import com.project.mapper.IVerifyMapper;
import com.project.service.IVerifyService;
import com.project.util.CreateToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class VerifyServiceImpl implements IVerifyService {

    @Autowired
    private IVerifyMapper mapper;

    @Override
    public String Login(String account, String password) {
        QueryWrapper<VerifyEntity> qw = new QueryWrapper<>();
        if (account !=null && account.length() !=0){
            qw.eq("account",account);
        }else {
            return "noland";
        }
        if (password !=null && password.length() !=0){
            qw.eq("password",password);
        }else {
            return "noland";
        }
        VerifyEntity verifyEntity =  mapper.selectOne(qw);
        if (verifyEntity != null){
            String jsonString = JSON.toJSONString(verifyEntity);

            String token= CreateToken.createToken(jsonString);
            return token;
        }
        return "noland";
    }
}
